<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "../../dashboard/mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "100%",
    },
    autoResize: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  watch: {
    chartData: {
      deep: true,
      handler(val) {
        this.setOptions(val);
      },
    },
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");
      this.setOptions(this.chartData);
    },
    setOptions({ expectedData, actualData } = {}) {
      this.chart.setOption({
        radar: {
          radius: "66%",
          // shape: 'circle',
          splitNumber: 3,
          splitLine: {
            lineStyle: {
                type: 'dashed', // 设置为虚线
                color: '#999'
            }
        },
          indicator: [
            { name: "沉降", max: 30 },
            { name: "气温", max: 40 },
            { name: "电阻", max: 20 },
            { name: "倾角", max: 20 },
            { name: "拉线", max: 30 },
          ],
        },
        textStyle: {
          color: "#fff",
          fontSize: 12,
        },
        series: [
          {
            name: "Budget vs spending",
            type: "radar",
            data: [
              {
                value: [20, 30, 14, 10, 20],
                name: "Actual Spending",
              },
            ],
            itemStyle: {
                color: '#00FFBD'
            },
            areaStyle: {
                opacity: 0.3
            }
          },
        ],
      });
    },
  },
};
</script>
